<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('新增物品')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-add" th:object="${goods}">
        <input type="hidden" name="goodsCover" id="imPath">
        <input type="hidden" name="id" id="id" th:value="*{id}">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">物品名称：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="*{goodsName}" type="text" name="goodsName" id="goodsName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类：</label>
            <div class="col-sm-8">
                <select class="form-control" name="categoryId" th:field="*{categoryId}"
                        th:with="type=${@dict.getType('si_service_catalog')}">
                    <option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">品牌：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="*{brand}" type="text" name="brand" id="brand" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div id="uploadBtn" class="col-sm-8 fileinput fileinput-new" data-provides="fileinput">
				<span class="btn btn-outline-secondary btn-file">
					<span class="fileinput-new">
						<a class="btn btn-warning btn-sm"><i class="fa fa-upload"></i>&nbsp;封面上传</a>
					</span>
					<input type="file" name="file" id="bpmnInfoinition" multiple>
				</span>
                <span class="fileinput-filename"></span>
                <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">数量：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="*{spec}" type="text" name="spec" id="spec" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea id="info" th:text="*{goodsDesc}" name="goodsDesc" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: jasny-bootstrap" />
<script type="text/javascript">
    var prefix = ctx + "/business/goods";

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-goods-add').serialize());
        }
    }

	$("#bpmnInfoinition").on("change.bs.fileinput",function () {
		var file = $("#bpmnInfoinition")[0].files[0];
		if (!file){
			$.modal.alertWarning("请上传一个文件");
			return;
		}
		var formData = new FormData();
		formData.append("file",file);
		$.ajax({
			url:prefix + "/uploading",
			type:"post",
			data:formData,
			contentType:false,
			processData:false,
			success:function (result) {
				if (result.code==0){
					$("#imPath").val(result.data);
				}else{
					$.modal.alertError(result.msg);
				}
			}
		})
	});
</script>
</body>
</html>
